package com.mdinfo.gw.door.web;

import com.alibaba.fastjson.JSON;
import com.mdinfo.base.common.bean.CommonResult;
import com.mdinfo.base.common.bean.Ref;
import com.mdinfo.gw.door.driver.DoorDriver;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

/**
 * Created by Administrator on 2018/1/31.
 */
@RestController
@RequestMapping("/app")
public class DoorDemoController {

    private Logger logger = LoggerFactory.getLogger(DoorDemoController.class);

    @Resource
    private DoorDriver doorDriver;

//    @RequestMapping("/open")
//    public CommonResult<Void> open(){
//        return doorDriver.openDoor();
//    }
//
//    @RequestMapping("/close")
//    public CommonResult<Void> close(){
//        return doorDriver.closeDoor();
//    }

    @RequestMapping("/aopu")
    public CommonResult<Void> aopu(HttpServletRequest request){
        System.out.println(request.getMethod());
        String s = null;
        try {
            s = IOUtils.toString(request.getInputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info(s);
        return Ref.ok();
    }

    @RequestMapping("/test01")
    public CommonResult<Void> test01(HttpServletRequest request){
        System.out.println("controller");
        try {
            String s = IOUtils.toString(request.getInputStream());
            System.out.println("c-s:"+s);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return Ref.ok();
    }

    @RequestMapping("/test02")
    public CommonResult<Void> test02(@RequestBody Person person){

        System.out.println("controller:"+JSON.toJSONString(person));
        return Ref.ok();
    }

//    @RequestMapping("/test03")
    @PostMapping("/compose/{id}")
    public CommonResult<Void> test03(@PathVariable String id, @RequestBody List<List<String>> list){
        System.out.println("id:"+id);
        System.out.println(JSON.toJSONString(list));
        return Ref.ok();
    }
}

class Person{
    private String name;
    private String age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }
}